package org.deng.vertx.springboot.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author 邓力宾
 * @date 2020/12/4 11:15
 * @desc 实体基类
 */
@Data
@Accessors(chain = true)
//@ApiModel("实体基类")
public class BaseEntity implements Serializable {

    private static final long serialVersionUID = 7613309951571827078L;
    @TableField(exist = true) //用于标识数据库是否存在该字段，默认true
    //(value = "id")
    private Long id;

    //(value = "是否删除", hidden = true)
    private Boolean deleted;

    //(value = "创建人", hidden = true)
    private Long createBy;


    //(value = "最后修改人", hidden = true)
    private Long updateBy;


    //(value = "创建时间")
    private LocalDateTime createTime;


    //(value = "最后修改时间", hidden = true)
    private LocalDateTime updateTime;


    /**
     * 设置创建属性
     * @param createBy 创建人
     */
    //(hidden = true)
    public void setCreateProperties(Long createBy){
        this.setId(null);
        if(this.getCreateTime() == null){
            this.setCreateTime(LocalDateTime.now());
        }
        this.setUpdateTime(this.getCreateTime());
        this.setCreateBy(createBy);
        this.setUpdateBy(createBy);
        this.setDeleted(false);
    }

    /**
     * 设置更新属性
     * @param updateBy 更新人
     */
    //(hidden = true)
    public void setUpdateProperties(Long updateBy){
        this.setUpdateTime(LocalDateTime.now());
        this.setUpdateBy(updateBy);

    }

}
